package com.eddie.hhcook;

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.eddie.hhcook.annotation.ContentView;
import com.eddie.hhcook.annotation.ViewInject;
import com.eddie.hhcook.annotation.ViewUtils;
import com.eddie.hhcook.base.BaseActivity;
import com.eddie.hhcook.view.circularfloatingactionmenu.library.FloatingActionButton;
import com.eddie.hhcook.view.circularfloatingactionmenu.library.FloatingActionMenu;
import com.eddie.hhcook.view.circularfloatingactionmenu.library.SubActionButton;


@ContentView(R.layout.activity_notice_content)
public class NoticeContentActivity extends BaseActivity implements View.OnClickListener{

    @ViewInject(R.id.home_left_menu)
    private ImageView home_left_menu;
    @Override
    public void initView() {
        ViewUtils.inject(this);
       // home_left_menu.setBackgroundResource(R.drawable.dm_icon_back);
        initCircleFloatingActionMenu();
    }


    @Override
    public void setListener() {
       home_left_menu.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.home_left_menu:
                finish();
                break;
        }
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    private void initCircleFloatingActionMenu() {

        final ImageView fabIconNew = new ImageView(this);
        fabIconNew.setBackgroundResource(R.drawable.ic_action_new_light);
        final FloatingActionButton rightLowerButton = new FloatingActionButton.Builder(this)
                .setContentView(fabIconNew)
               .setBackgroundDrawable(R.drawable.button_action_red_selector)
                .build();

        SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(this);
        rLSubBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_blue_selector));
        ImageView rlIcon1 = new ImageView(this);
        ImageView rlIcon2 = new ImageView(this);
        ImageView rlIcon3 = new ImageView(this);
        ImageView rlIcon4 = new ImageView(this);

        int blueSubActionButtonSize = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_size);
        FrameLayout.LayoutParams blueParams = new FrameLayout.LayoutParams(blueSubActionButtonSize, blueSubActionButtonSize);
        rLSubBuilder.setLayoutParams(blueParams);

        rlIcon1.setBackgroundResource(R.drawable.ic_action_chat_light);
        rlIcon2.setBackgroundResource(R.drawable.ic_action_camera_light);
        rlIcon3.setBackgroundResource(R.drawable.ic_action_video_light);
        rlIcon4.setBackgroundResource(R.drawable.ic_action_place_light);

        SubActionButton s = rLSubBuilder.setContentView(rlIcon1).build();
        final FloatingActionMenu rightLowerMenu = new FloatingActionMenu.Builder(this)
                .addSubActionView(s)
                .addSubActionView(rLSubBuilder.setContentView(rlIcon2).build())
                .addSubActionView(rLSubBuilder.setContentView(rlIcon3).build())
                .addSubActionView(rLSubBuilder.setContentView(rlIcon4).build())
                .attachTo(rightLowerButton)
                .build();


        // Listen menu open and close events to animate the button content view
        rightLowerMenu.setStateChangeListener(new FloatingActionMenu.MenuStateChangeListener() {

            @Override
            public void onMenuOpened(FloatingActionMenu menu) {
                // Rotate the icon of rightLowerButton 45 degrees clockwise
                fabIconNew.setRotation(0);
                PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 45);
                ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(fabIconNew, pvhR);
                animation.start();
            }

            @Override
            public void onMenuClosed(FloatingActionMenu menu) {
                // Rotate the icon of rightLowerButton 45 degrees counter-clockwise
                fabIconNew.setRotation(45);
                PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 0);
                ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(fabIconNew, pvhR);
                animation.start();
            }
        });


    }
}
